package com.hck.domain.health.model.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 健康檢查記錄領域實體
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class HealthCheckRecordEntity {
    
    private Long id;
    private Long userId;
    private Date checkDate;
    private String checkType; // 檢查類型：血壓、血糖、體檢等
    private Integer systolicPressure; // 收縮壓
    private Integer diastolicPressure; // 舒張壓
    private Integer heartRate; // 心率
    private BigDecimal bloodSugar; // 血糖
    private BigDecimal cholesterol; // 膽固醇
    private BigDecimal triglycerides; // 甘油三酯
    private BigDecimal bmi; // BMI指數
    private BigDecimal bodyFatRate; // 體脂率
    private String otherIndicators; // 其他指標(JSON)
    private String doctorAdvice; // 醫生建議
    private Date createTime;
    private Date updateTime;
    
    /**
     * 檢查血壓是否正常
     */
    public boolean isBloodPressureNormal() {
        if (systolicPressure == null || diastolicPressure == null) {
            return false;
        }
        // 正常血壓：收縮壓90-140，舒張壓60-90
        return systolicPressure >= 90 && systolicPressure <= 140 &&
               diastolicPressure >= 60 && diastolicPressure <= 90;
    }
    
    /**
     * 檢查心率是否正常
     */
    public boolean isHeartRateNormal() {
        if (heartRate == null) return false;
        // 正常心率：60-100次/分
        return heartRate >= 60 && heartRate <= 100;
    }
    
    /**
     * 檢查血糖是否正常
     */
    public boolean isBloodSugarNormal() {
        if (bloodSugar == null) return false;
        // 空腹血糖正常值：3.9-6.1 mmol/L
        return bloodSugar.compareTo(new BigDecimal("3.9")) >= 0 && 
               bloodSugar.compareTo(new BigDecimal("6.1")) <= 0;
    }
    
    /**
     * 獲取血壓等級
     */
    public String getBloodPressureLevel() {
        if (!isBloodPressureNormal()) {
            if (systolicPressure > 140 || diastolicPressure > 90) {
                return "高血壓";
            } else if (systolicPressure < 90 || diastolicPressure < 60) {
                return "低血壓";
            }
        }
        return "正常";
    }
}